﻿using System;

namespace FDEE.Model
{
    /// <summary>
    /// L 锚固(L=A+B+C-r/2-d)
    /// </summary>
    public class MLRebarRecord : RebarBase
    {
        public MLRebarRecord(int mBarMark, int sBarMark, string cBarMark, eDB diameter, int quantity, eShapeType shapeConfg,
            int aa,int bb,int cc,int rr) 
            : base(mBarMark, sBarMark, cBarMark, diameter, quantity, shapeConfg)
        {
            if (aa < 0 || bb < 0 || cc < 0 || rr < 0)
            {
                throw new Exception("L锚固筋结果异常请查询原因！");
            }
            A = aa;
            B = bb;
            C = cc;
            r = rr;
            d = 32;
            Formula = "L=A+B+C-r/2-d";
        }
        public MLRebarRecord(int mBarMark, int sBarMark, string cBarMark, eDB diameter, int quantity, eShapeType shapeConfg,
        int aa, int bb, int rr)
        : base(mBarMark, sBarMark, cBarMark, diameter, quantity, shapeConfg)
        {
            if (aa < 0 || bb < 0 || rr < 0)
            {
                throw new Exception("L锚固筋结果异常请查询原因！");
            }
            A = aa;
            B = bb;
            r = rr;
            d = 32;
            Formula = "L=A+B+C-r/2-d";
        }
        public override void SetLength()
        {
            Length = Math.Round((A + B + C - 0.5 * r - (int)Diameter)*0.001, 3, MidpointRounding.AwayFromZero);
            if (Length > 12 || Length < 0)
            {
                throw new Exception("L锚固长度计算异常，请查找原因！");
            }
        }
    }
    /// <summary>
    /// L(L=A+B-r/2-d) 
    /// </summary>
    public class MLADDRebarRecord : RebarBase
    {

        public MLADDRebarRecord(int mBarMark, int sBarMark, string cBarMark, eDB diameter, int quantity, eShapeType shapeConfg,
        double aa, double bb, int rr)
        : base(mBarMark, sBarMark, cBarMark, diameter, quantity, shapeConfg)
        {
            if (aa < 0 || bb < 0 || rr < 0)
            {
                throw new Exception("L锚固筋结果异常请查询原因！");
            }
            A = aa;
            B = bb;
            r = rr;
            d = ((int)diameter);
            Formula = "L=A+B-r/2-d";
        }
        public override void SetLength()
        {
            Length = Math.Round((A + B - 0.5 * r - (int)Diameter) * 0.001, 3, MidpointRounding.AwayFromZero);
            if (Length > 12 || Length < 0)
            {
                throw new Exception("L锚固长度计算异常，请查找原因！");
            }
        }
    }

    /// <summary>
    /// L (L=A+B-r-2d)
    /// </summary>
    public class MLCRebarRecord : RebarBase
    {
        /// <summary>
        /// MC 型钢筋长度重量计算 - 直筋，可能存在两端搭接和锚固承台（其他构件）
        /// </summary>
        /// <param name="mBarMark">钢筋主编号，例如1</param>
        /// <param name="sBarMark">钢筋次编号，例如1.1，默认为0</param>
        /// <param name="cBarMark">钢筋字符编号，例如1a，默认为空</param>
        /// <param name="diameter">钢筋直径，按eDB选取</param>
        /// <param name="A">外边缘到外边缘长度</param>
        /// <param name="n">弯钩长度</param>
        /// <param name="r">折减圆弧长度</param>
        /// <param name="d">钢筋直径</param>
        /// <param name="quantity">数量</param>
        /// <param name="shapeConfig"></param>
        public MLCRebarRecord(int mBarMark, int sBarMark, string cBarMark, eDB diameter,
            int a, int b, int quantity, eShapeType shapeConfig)
            : base(mBarMark, sBarMark, cBarMark, diameter, quantity, shapeConfig)
        {
            if (a < 0 || b < 0)
            {
                throw new Exception("ML筋结果异常请查询原因！");
            }
            A = a;
            B = b;
            //C = c;
            this.r = RebarKnowledge.GerRadius(diameter);
            this.d = PublicEnumItems.GeteDBData(diameter.ToString());
            this.Formula = "L=A+B-r-2d";
        }


        public override void SetLength()
        {
            Length = Math.Round((A + B - r - 2 * d) * 0.001, 3, MidpointRounding.AwayFromZero);
            if (Length > 12 || Length < 0)
            {
                throw new Exception("ML长度计算异常，请查找原因！");
            }
        }
    }

    /// <summary>
    ///L特殊3S墩柱 L=A+B+C+D+E-r/2-d 
    /// </summary>
    public class MLSDRebarRecord : RebarBase
    {
        public MLSDRebarRecord(int mBarMark, int sBarMark, string cBarMark, eDB diameter, int quantity, eShapeType shapeConfg,
            int aa, int bb, int cc,int dd,int ee, int rr)
            : base(mBarMark, sBarMark, cBarMark, diameter, quantity, shapeConfg)
        {
            if (aa < 0 || bb < 0 || cc < 0 || rr < 0)
            {
                throw new Exception("L锚固筋结果异常请查询原因！");
            }
            A = aa;
            B = bb;
            C = cc;
            D = dd;
            E = ee;
            r = rr;
            d = (int)diameter;
            Formula = "L=A+B+C+D+E-r/2-d";
        }
 
        public override void SetLength()
        {
            Length = Math.Round((A + B + C+D+E - 0.5 * r - (int)Diameter) * 0.001, 3, MidpointRounding.AwayFromZero);
            if (Length > 12 || Length < 0)
            {
                throw new Exception("L锚固长度计算异常，请查找原因！");
            }
        }
    }

    /// <summary>
    /// 直线(L=A+B)
    /// </summary>
    public class MLSRebarRecord : RebarBase
    {
        public MLSRebarRecord(int mBarMark, int sBarMark, string cBarMark, eDB diameter, int quantity, eShapeType shapeConfg,
            int aa, int bb)
            : base(mBarMark, sBarMark, cBarMark, diameter, quantity, shapeConfg)
        {
            if (aa < 0 || bb < 0 )
            {
                throw new Exception("直线锚固筋结果异常请查询原因！");
            }
            A = aa;
            B = bb;
            Formula = "L=A+B";
        }

        public override void SetLength()
        {
            Length = Math.Round((A + B) * 0.001, 3, MidpointRounding.AwayFromZero);
            if (Length > 12 || Length < 0)
            {
                throw new Exception("直线锚固计算异常，请查找原因！");
            }
        }
    }


    /// <summary>
    /// L闪电A+B+C+D
    /// </summary>
    public class MLZRebarRecord : RebarBase
    {
        public MLZRebarRecord(int mBarMark, int sBarMark, string cBarMark, eDB diameter, int quantity, eShapeType shapeConfg,
            int aa, int bb, int cc, int dd)
            : base(mBarMark, sBarMark, cBarMark, diameter, quantity, shapeConfg)
        {
            if (aa < 0 || bb < 0 || cc < 0 || dd < 0)
            {
                throw new Exception("闪电筋结果异常请查询原因！");
            }
            A = aa;
            B = bb;
            C = cc;
            D = dd;
            Formula = "L=A+B+C+D";
        }

        public override void SetLength()
        {
            Length = Math.Round((A + B+C+D) * 0.001, 3, MidpointRounding.AwayFromZero);
            if (Length > 12 || Length < 0)
            {
                throw new Exception("闪电筋长度计算异常，请查找原因！");
            }
        }
    }

    /// <summary>
    /// 直闪电L=A+B+C
    /// </summary>
    public class MSZRebarRecord : RebarBase
    {
        public MSZRebarRecord(int mBarMark, int sBarMark, string cBarMark, eDB diameter, int quantity, eShapeType shapeConfg,int aa=12000-45+32)
            : base(mBarMark, sBarMark, cBarMark, diameter, quantity, shapeConfg)
        {
            if (aa < 0)
            {
                throw new Exception("小闪电直筋结果异常请查询原因！");
            }
            int cap = 2400;
            if (diameter == eDB.DB28)
                cap = 1800;
            A = aa - 248 - cap;
            B = 250;
            //A = aa - 32 - 2400;
            //B = 45;

            C = cap;
            Formula = "L=A+B+C";
        }
        public MSZRebarRecord(int mBarMark, int sBarMark, string cBarMark, eDB diameter, int quantity, eShapeType shapeConfg, double aa , double bb, double cc)
           : base(mBarMark, sBarMark, cBarMark, diameter, quantity, shapeConfg)
        {
            if (aa < 0|| bb < 0|| cc < 0)
            {
                throw new Exception("小闪电直筋结果异常请查询原因！");
            }
            //A = 12000-45-2400;
            A = aa;
            B = bb;
            C = cc;
            Formula = "L=A+B+C";
        }

        public override void SetLength()
        {
            Length = Math.Round((A + B + C) * 0.001, 3, MidpointRounding.AwayFromZero);
            if (Length > 12 || Length < 0)
            {
                throw new Exception("小闪电直筋长度计算异常，请查找原因！");
            }
        }
    }
}
